<template>
  <div class="product-management">
    <el-card class="page-card">
      <template #header>
        <div class="card-header">
          <span class="page-title">商品路线管理</span>
          <span class="page-subtitle">统一商品管理路线信息、替换规则和城市景点数据</span>
        </div>
      </template>

      <el-tabs v-model="activeTab" type="card" class="management-tabs">
        <el-tab-pane label="路线管理" name="products">
          <template #label>
            <el-icon><ShoppingBag /></el-icon>
            <span>路线管理</span>
          </template>
          <div class="tab-content">
            <ProductList />
          </div>
        </el-tab-pane>

        <el-tab-pane label="替换规则" name="rules">
          <template #label>
            <el-icon><Setting /></el-icon>
            <span>替换规则</span>
          </template>
          <div class="tab-content">
            <RuleList />
          </div>
        </el-tab-pane>

        <el-tab-pane label="城市景点管理" name="attractions">
          <template #label>
            <el-icon><MapLocation /></el-icon>
            <span>城市景点管理</span>
          </template>
          <div class="tab-content">
            <CityAttraction />
          </div>
        </el-tab-pane>

        <el-tab-pane label="自定义行程内容管理" name="custom-content">
          <template #label>
            <el-icon><MapLocation /></el-icon>
            <span>行程内容管理</span>
          </template>
          <div class="tab-content">
            <CustomContentManagement />
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ShoppingBag, Setting, MapLocation } from '@element-plus/icons-vue'
import ProductList from '@/views/product/ProductList.vue'
import RuleList from '@/views/product/RuleList.vue'
import CityAttraction from "@/views/product/CityAttraction.vue"
import CustomContentManagement from "@/views/product/CustomContentManagement.vue";

// 当前激活的标签页
const activeTab = ref('products')

// 根据路由参数设置默认标签页
const route = useRoute()
if (route.query.tab) {
  activeTab.value = route.query.tab
}

// 监听标签页切换，更新URL参数（可选）
const router = useRouter()
watch(activeTab, (newTab) => {
  router.replace({
    query: {
      ...route.query,
      tab: newTab
    }
  })
})
</script>

<style scoped>
.product-management {
  height: 100%;
}

.page-card {
  height: 100%;
  --el-card-padding: 20px;
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}

.page-subtitle {
  font-size: 14px;
  color: #909399;
}

.management-tabs {
  height: calc(100vh - 220px);
}

.management-tabs :deep(.el-tabs__content) {
  height: calc(100% - 50px);
  overflow: hidden;
}

.tab-content {
  height: 100%;
  overflow: auto;
}

.management-tabs :deep(.el-tab-pane) {
  height: 100%;
}

.management-tabs :deep(.el-tabs__item) {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
}

.management-tabs :deep(.el-tabs__nav-wrap) {
  background: #f5f7fa;
  border-radius: 6px 6px 0 0;
}

.management-tabs :deep(.el-tabs__active-bar) {
  display: none;
}

.management-tabs :deep(.el-tabs__item.is-active) {
  background: #409eff;
  color: white;
  border-color: #409eff;
}

.management-tabs :deep(.el-tabs__item:hover) {
  color: #409eff;
}

.management-tabs :deep(.el-tabs__item.is-active:hover) {
  color: white;
}
</style>